package com.zhangtai.Neusoft.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.zhangtai.Neusoft.constVo.EmployeeChangeConst;
import com.zhangtai.Neusoft.vo.*;
import com.zhangtai.modules.controller.admin.JobController;
import com.zhangtai.modules.dao.ImgUrlDao;
import com.zhangtai.modules.entity.common.ImgUrlEntity;
import com.zhangtai.modules.entity.contract.ContractMangerEntity;
import com.zhangtai.modules.entity.employee.*;
import com.zhangtai.modules.entity.regular.RegularBpmEntity;
import com.zhangtai.modules.entity.transfer.TransferInfoEntity;
import com.zhangtai.modules.service.dimission.DimissionSettlementService;
import com.zhangtai.modules.service.employee.*;
import com.zhangtai.modules.service.transfer.TransferInfoService;
import com.zhangtai.mq.MessageSender;
import com.zhangtai.mq.config.EmployeeChangeMqConfig;
import com.zhangtai.mq.listener.GetUserCodeListener;
import com.zhangtai.utils.BeanUtilsMabach;
import com.zhangtai.utils.DateUtils;
import com.zhangtai.utils.R;
import com.zhangtai.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;

@RestController
@Slf4j
public class NeusoftEmployeeChangeService {
    @Autowired
    private EmployeeInfoService employeeInfoService;
    @Autowired
    private JobController jobController;

    @Autowired
    private EmployeeEducationService employeeEducationService;
    @Autowired
    private EmployessSocietyexperienceService employessSocietyexperienceService;
    @Autowired
    private FamilyMemberService familyMemberService;
    @Autowired
    private EmployeeInorgnameService employeeInorgnameService;
    @Autowired
    private RelativeRecordsService relativeRecordsService;


    @Value("${neu.applyUrl}")
    private String neuUrl;
    @Autowired
    private MessageSender messageSender;
    @Autowired
    private EmployeeChangeMqConfig employeeChangeMqConfig;
    @Autowired
    private TransferInfoService transferInfoService;
    @Autowired
    private ImgUrlDao imgUrlDao;
    @Autowired
    private GetUserCodeListener getUserCodeListener;
    @Autowired
    private DimissionSettlementService dimissionSettlementService;

    @ApiOperation("入职员工异动")
    @Async("Neusoft")
    public R uploadEmployeeChange(EmployeeInfoEntity entity){
        //如果没有工号调用东软接口插入工号
        if(StringUtils.isEmpty(entity.getCode())){
            log.info("{}插入工号",entity.getName());
//            entity.setCode(getUserCodeListener.getUserCode(entity.getOid()).getData());
        }
        EmployeeBaseVo vo = new EmployeeBaseVo();
        vo.setPr(entity.getProfessionalType());
        vo.setPrnum(entity.getPositionStar());
        vo.setCode(entity.getCode());
        vo.setName(entity.getName());
        vo.setGender(entity.getGender());
        vo.setOrgId(entity.getOrgId());
        vo.setUnitId(entity.getUnitId());
        vo.setJobId(entity.getJobId());
        if(entity.getIsReinstate().equals(1)||entity.getIsReinstate().equals(3)){
            vo.setEmployeeStatus("3");
        }else {
            if("5".equals(entity.getJobType())){
                vo.setEmployeeStatus("9");
            }else{
                vo.setEmployeeStatus("0");
            }
        }
        vo.setHiredate(DateUtils.format(entity.getHiredate()));
        vo.setAge(DateUtils.yearsBetween(entity.getBirthday(),new Date())+"");
        vo.setIdcard(entity.getIdcard());
        String address = "";
//        if(!StringUtils.isEmpty(entity.getNativeplaceProvince())){
//            address +=jobController.nativeplace.get(Long.parseLong(entity.getNativeplaceProvince()));
//        }
//        if(!StringUtils.isEmpty(entity.getNativeplace())){
////            address +=jobController.nativeplace.get(Long.parseLong(entity.getNativeplace()));
//            address +=jobController.nativeplace.get(entity.getNativeplace());
//
//        }
        vo.setNativeAddress(entity.getNativeplace());
        vo.setBirthday(DateUtils.format(entity.getBirthday()));
        vo.setRegresidence(entity.getRegresidence());
//        vo.setNation("1");
        vo.setNationality(entity.getNationality());
        vo.setNation(entity.getNation());
        vo.setAddress(entity.getAddress());
        vo.setMyphone(entity.getMobile());
        vo.setPolity(entity.getPolity());
        vo.setEmail(entity.getPrivatemail());
        vo.setHealth(entity.getHealthstatus());
        vo.setTuiwu(entity.getDisbandment());
        vo.setDangan(entity.getRecordFileAddress());
        vo.setCenterPeople(ObjectUtils.isEmpty(entity.getIscentreprincipal())?"":entity.getIscentreprincipal());
        vo.setPetpeople(ObjectUtils.isEmpty(entity.getIsdepartmentprincipa())?"":entity.getIsdepartmentprincipa());
//        vo.setZhuanzheng(DateUtils.format(entity.getRegularDay()));
//        vo.setIsWorker("0");
//        vo.setSituation();
        vo.setYgStyle(entity.getJobType());
        vo.setRecruitStyle("7".equals(entity.getChannel())?"9":entity.getChannel());
        vo.setRecruitWeb(entity.getRecruitmentWeb());
        vo.setBeginWorkdate(DateUtils.format(entity.getBeginworkdate()));
        vo.setGroomName(entity.getOuterReferrer());
        vo.setGroomEmpId(entity.getInnerReferrer());
        vo.setMarital(entity.getMarital());
        if(entity.getJobLevelType().equals(1)){
            vo.setProfessionalLevel(getCode(entity.getJobLevelId()));
        }else{
            vo.setRanks(getCode(entity.getJobLevelId()));
        }
        vo.setJoinJobDate(DateUtils.format(entity.getHiredate()));
        vo.setJoinUnitDate(DateUtils.format(entity.getHiredate()));
        vo.setWhether(entity.getIsReinstate().equals(3)||entity.getIsReinstate().equals(1)?"1":"0");
        List<Integer> type = new ArrayList<>();
        type.add(0);
        type.add(1);
        type.add(2);
        type.add(3);
        type.add(4);
        type.add(5);
        type.add(6);
        type.add(10);
        type.add(11);
        Map<Integer,String> typeName = new HashMap<>();
        typeName.put(0,"银行流水");
        typeName.put(1,"头像");
        typeName.put(2,"毕业证");
        typeName.put(3,"学位证");
        typeName.put(4,"离职证明");
        typeName.put(5,"体检报告");
        typeName.put(6,"身份证正反面");
        typeName.put(10,"职称证书");
        typeName.put(11,"其他附件");
        List<ImgUrlEntity> urlEntityList = imgUrlDao.selectList(new QueryWrapper<ImgUrlEntity>().eq("is_delete",0).eq("oid",entity.getOid()).in("type",type));
        List<FileVo> fileList = new ArrayList<>();
        for(ImgUrlEntity url:urlEntityList){
            fileList.addAll(getFiles(url.getUrl(),typeName.get(url.getType())));
        }
        //不传 只存共享数据
        //vo.setAnnexInformation(fileList);
        EmployeeChangeVo changeVo = new EmployeeChangeVo();
        changeVo.setEduList(getEducationList(entity.getOid(),entity.getCode(),vo));
        changeVo.setFamilyList(getFamilyList(entity.getOid(),entity.getCode(),vo));
        changeVo.setGrouptList(getGroupList(entity.getOid(),entity.getCode()));
        changeVo.setInFamilyList(getRelativeList(entity.getOid(),entity.getCode()));
        changeVo.setWorkList(getSocietyList(entity.getOid(),entity.getCode()));
        changeVo.setEmpBaseInfoVO(vo);
        sendMq(changeVo, EmployeeChangeConst.CHANGE_TYPE_NEW);
        return R.ok();
    }

    /**
     * 教育经历
     * @param oid
     * @param baseVo
     * @return
     */
    public List<EducationVo> getEducationList(Long oid,String code,EmployeeBaseVo baseVo){
        List<EmployeeEducationEntity> entityList = employeeEducationService.findEmployeeEducationListByOid(oid);
        List<EducationVo> voList = new ArrayList<>();
        for(EmployeeEducationEntity entity:entityList){
            EducationVo vo = BeanUtilsMabach.doToDto(entity,EducationVo.class);
            vo.setId(entity.getOid());
            vo.setEmpCode(code);
            if(entity.getStudystyle()!=null) {
                vo.setStudyStyle(Integer.parseInt(entity.getStudystyle()) < 10 ? "0" + entity.getStudystyle() : entity.getStudystyle());
            }
            vo.setDegree(entity.getDegree());
            vo.setGrade(entity.getGrade());
            vo.setGraduateDate(DateUtils.format(entity.getGraduatedate()));
            vo.setSchoolDate(DateUtils.format(entity.getSchooldate()));
            vo.setCertificateNum(entity.getGradeNum());
            if(entity.getIstopgrade()!=null) {
                vo.setIsTopGrade(entity.getIstopgrade());
            }

            if(entity.getIstopgrade()!=null) {
                if (entity.getIstopgrade().equals("1")) {
                    baseVo.setKnowledge(entity.getDegree());
                    baseVo.setSchool(entity.getSchool());
                }
            }
            voList.add(vo);
        }
        return voList;
    }

    /**
     * 工作经验
     * @param oid
     * @return
     */
    public List<SocietyVo> getSocietyList(Long oid,String code){
        List<SocietyVo> voList = new ArrayList<>();
       List<EmployessSocietyexperienceEntity> entityList =  employessSocietyexperienceService.getByEmpId(oid);
        for(EmployessSocietyexperienceEntity entity:entityList){
            SocietyVo vo = BeanUtilsMabach.doToDto(entity,SocietyVo.class);
            vo.setId(entity.getOid());
            vo.setBeginDate(DateUtils.format(entity.getBegindate()));
            vo.setEndDate(DateUtils.format(entity.getEnddate()));
            vo.setEmpCode(code);
            vo.setWitnessContact(entity.getWitnesscontact());
            vo.setRenzhigangwei(entity.getResponsibility());
            voList.add(vo);
        }
        return voList;
    }

    /**
     * 家庭关系
     * @param oid
     * @param baseVo
     * @return
     */
    public List<FamilyVo> getFamilyList(Long oid,String code,EmployeeBaseVo baseVo){
        List<FamilyMemberEntity> entityList = familyMemberService.getListByEmpId(oid);
        List<FamilyVo> voList = new ArrayList<>();
        for(FamilyMemberEntity entity:entityList){
            FamilyVo vo = BeanUtilsMabach.doToDto(entity,FamilyVo.class);
            vo.setId(entity.getOid());
            vo.setEmpCode(code);
            vo.setTl(entity.getPhone());
            vo.setLianxiren(entity.getIsEmergencyContact());
            if(entity.getIsEmergencyContact().equals("1")){
                baseVo.setLianxiren(entity.getName());
                baseVo.setRel(entity.getRelation());
                baseVo.setLixirenPhone(entity.getPhone());
            }
            voList.add(vo);
        }
        return voList;
    }

    /**
     * 合同信息
     * @param entity
     * @return
     */
    @Async("Neusoft")
    public void uploadContract(ContractMangerEntity entity){
        Map<Integer,String> typeMap = new HashMap<>();
        typeMap.put(1,"新签合同");
        typeMap.put(2,"续签合同");
        typeMap.put(3,"解除协议");
        typeMap.put(4,"调动新签");
        EmployeeInfoEntity infoEntity = employeeInfoService.getByIdE(entity.getOid());
        List<ContractVo> voList = new ArrayList<>();
        ContractVo vo = new ContractVo();
        vo.setBeginDate(DateUtils.format(entity.getContractBeginDate()));
        vo.setCode(entity.getContractNo());
        vo.setContractJiafang(Integer.parseInt(jobController.company.get(entity.getEmployerCompany())));
        vo.setContractTermType("6".equals(entity.getContractTimeType())?"2":"1");
        vo.setContractType("1");
        vo.setExpireDate(DateUtils.format(entity.getContractEndDate()));
        vo.setName(typeMap.get(entity.getType()));
        vo.setVersionNum("0");
        vo.setProBeginDate(DateUtils.format(entity.getContractBeginDate()));
        vo.setProEndDate(DateUtils.format(DateUtils.addDateDays(DateUtils.addDateMonths(entity.getContractBeginDate(),infoEntity.getProbationday()),-1)));
        vo.setProMonths(infoEntity.getProbationday().toString());
        vo.setEmpCode(entity.getCode());
        vo.setId(entity.getId());
        vo.setContractOssUrl(entity.getContractOssUrl());
        vo.setSignedDate(DateUtils.format(entity.getSignDate()));
        Integer status = (entity.getType() == 1 || entity.getType() == 4) ? 1 : entity.getType() == 2 ? 2 : 3;
        vo.setContractStatus(String.valueOf(status));
        voList.add(vo);
        ContractListVo listVo = new ContractListVo();
        listVo.setEmpContractInfoVOs(voList);
        sendMq(listVo, EmployeeChangeConst.CHANGE_TYPE_CONTRACT);
    }

    /**
     * 党派信息
     * @param oid
     * @return
     */
    public List<GroupVo> getGroupList(Long oid,String code){
        List<EmployeeInorgnameEntity> entityList = employeeInorgnameService.getByEmpId(oid);
        List<GroupVo> list = new ArrayList<>();
        for(EmployeeInorgnameEntity entity:entityList){
            GroupVo vo  = new GroupVo();
            vo.setEmpoid(entity.getEmpoid());
            vo.setEmpCode(code);
            vo.setId(entity.getId());
            vo.setPtype(entity.getPolity());
            vo.setUnitId(entity.getInorgname());
            vo.setUpDate(DateUtils.format(entity.getJoinDay()));
            list.add(vo);
        }
        return list;
    }

    /**
     * 亲属关系
     * @param oid
     * @return
     */
    public List<RelativeVo> getRelativeList(Long oid,String code){
       List<RelativeRecordsEntity> entityList =  relativeRecordsService.getByOid(oid);
       List<RelativeVo> voList = new ArrayList<>();
       for(RelativeRecordsEntity entity:entityList){
           RelativeVo vo = new RelativeVo();
           vo.setEmpoid(entity.getOid());
           vo.setQinshuIDCard(entity.getIdcard());
           vo.setDanwei(entity.getUnit());
           vo.setId(entity.getId());
           vo.setEmpCode(code);
           vo.setRelatives(entity.getRelative());
//           vo.setRelativesName(entity.getRelative());
           vo.setQinshuName(entity.getName());
           if(!ObjectUtils.isEmpty(entity.getIsDirectRelative())){
               vo.setIsDirectRelative(entity.getIsDirectRelative());
           }
           vo.setJob(entity.getJob());
           voList.add(vo);
       }
       return voList;
    }

    @ApiOperation("调动异动更新接口")
    @Async("Neusoft")
    public R uploadTransferChange(TransferInfoEntity entity, BigDecimal baseSalary,BigDecimal moduleSalary){
        Map<Integer,String> transferType = new HashMap<>();
        transferType.put(0,"3");
        transferType.put(2,"6");
        transferType.put(3,"5");
        transferType.put(4,"4");
        TransferVo vo = new TransferVo();
        String name = entity.getName();
        vo.setTitle(name+"的调动申请");
        vo.setApplyDate(DateUtils.format(entity.getCreateTime()));
        vo.setApplyCode(entity.getApplyCode());
        vo.setApplyId(entity.getTransferId());
        vo.setBeginDate(DateUtils.format(entity.getBeginTransferDate()));
        vo.setEmpCode(entity.getUserCode());
        vo.setEmpName(name);
        vo.setTransferWay("2");
        vo.setTransferType(transferType.get(entity.getTransferType()));
        vo.setNowDeptId(entity.getBeforeDepartmentId());
        vo.setNowJobId(entity.getBeforeJobId());
        vo.setNrDeptId(entity.getAfterDepartmentId());
        vo.setNrJobId(entity.getAfterJobId());
        vo.setNowOrgId(entity.getBeforeOrgId());
        vo.setNrOrgId(entity.getAfterOrgId());
        if(entity.getBeforeJobLevelType().equals(1)){
            vo.setNowZYZJ(getCode(entity.getBeforeJobLevelId()));
        }else{
            vo.setNowGLZJ(getCode(entity.getBeforeJobLevelId()));
        }
        if(entity.getAfterJobLevelType().equals(1)){
            vo.setNdZYZJ(getCode(entity.getAfterJobLevelId()));
        }else{
            vo.setNdGLZJ(getCode(entity.getAfterJobLevelId()));
        }
        vo.setBeginDate(DateUtils.format(entity.getBeginTransferDate()));
        vo.setEndDate(DateUtils.format(entity.getEndTransferDate()));
        vo.setNdDate(ObjectUtils.isEmpty(entity.getRealHireDate())?DateUtils.format(entity.getBeginTransferDate()):DateUtils.format(entity.getRealHireDate()));
        vo.setReason(entity.getReason());
        vo.setYxgd(ObjectUtils.isEmpty(baseSalary)?"":baseSalary.toString());
        vo.setEmpMod(ObjectUtils.isEmpty(moduleSalary)?"":moduleSalary.toString());
        vo.setFiledoc(getFiles(entity.getFileUrl(),name+"的调动附件"));
        sendMq(vo,EmployeeChangeConst.CHANGE_TYPE_TRANSFER);
        return R.ok();
    }

    @ApiOperation("调动异动更新接口")
    @Async("Neusoft")
    public R uploadPromotionChange(PromotionEntity entity){
        Map<Integer,String> promotionType = new HashMap<>();
        promotionType.put(1,"5");
        promotionType.put(2,"4");
        TransferVo vo = new TransferVo();
        String name = entity.getName();
        vo.setTitle(name+"的晋升申请");
        vo.setApplyDate(DateUtils.format(entity.getCreateTime()));
        vo.setApplyCode(entity.getApplierCode());
        vo.setApplyId(entity.getPromotionId());
        vo.setBeginDate(DateUtils.format(entity.getBeginExpeditionDate()));
        vo.setEmpCode(entity.getCode());
        vo.setEmpName(name);
        vo.setTransferWay("2");
        if(entity.getPromotionKind().equals(0)){
            vo.setTransferType(promotionType.get(entity.getPromotionType()));
        }else{
            vo.setTransferType("6");
        }
        vo.setNowDeptId(entity.getBeforeUnitId());
        vo.setNowJobId(entity.getBeforeJobId());
        vo.setNrDeptId(entity.getAfterUnitId());
        vo.setNrJobId(entity.getAfterJobId());
        vo.setNowOrgId(entity.getBeforeOrgId());
        vo.setNrOrgId(entity.getAfterOrgId());
        if(entity.getBeforeJobType().equals("1")){
            vo.setNowZYZJ(getCode(entity.getBeforeJobLevelId()));
        }else{
            vo.setNowGLZJ(getCode(entity.getBeforeJobLevelId()));
        }
        if(entity.getAfterJobType().equals("1")){
            vo.setNdZYZJ(getCode(entity.getAfterJobLevelId()));
        }else{
            vo.setNdGLZJ(getCode(entity.getAfterJobLevelId()));
        }
        if(ObjectUtils.isEmpty(entity.getBeginExpeditionDate())){
            vo.setBeginDate(DateUtils.format(entity.getPromotionDate()));
            vo.setNdDate(DateUtils.format(entity.getPromotionDate()));
        }else{
            vo.setBeginDate(DateUtils.format(entity.getBeginExpeditionDate()));
            vo.setNdDate(DateUtils.format(entity.getBeginExpeditionDate()));
        }
        vo.setEndDate("2200-12-31 00:00:00");
        vo.setReason(entity.getReason());
//        vo.setYxgd(ObjectUtils.isEmpty(baseSalary)?"":baseSalary.toString());
//        vo.setEmpMod(ObjectUtils.isEmpty(moduleSalary)?"":moduleSalary.toString());
//        vo.setFiledoc(getFiles(entity.getFileUrl(),name+"的晋升附件"));
        sendMq(vo,EmployeeChangeConst.CHANGE_TYPE_TRANSFER);
        return R.ok();
    }

    @ApiOperation("借调异动更新接口")
    @Async("Neusoft")
    public R uploadSecondment(EmployeeSecondmentEntity entity){
        EmployeeInfoEntity infoEntity = employeeInfoService.getByIdE(entity.getOid());
        TransferVo vo = new TransferVo();
        vo.setTitle(entity.getName()+"的借调申请");
        vo.setApplyDate(DateUtils.format(entity.getCreateTime()));
        vo.setApplyCode(entity.getCreateCode());
        vo.setApplyId(entity.getId());
        vo.setEmpCode(entity.getCode());
        vo.setEmpName(entity.getName());
        vo.setTransferWay("1");
        vo.setNowDeptId(entity.getUnitId());
        vo.setNowJobId(entity.getJobId());
        vo.setNrDeptId(entity.getSecondmentUnitId());
        vo.setNrJobId(entity.getSecondmentJobId());
        vo.setNowOrgId(entity.getOrgId());
        vo.setNrOrgId(entity.getSecondmentOrgId());
        if(infoEntity.getJobLevelType().equals(1)){
            vo.setNowZYZJ(getCode(infoEntity.getJobLevelId()));
            vo.setNdZYZJ(getCode(infoEntity.getJobLevelId()));
        }else{
            vo.setNowGLZJ(getCode(infoEntity.getJobLevelId()));
            vo.setNdGLZJ(getCode(infoEntity.getJobLevelId()));
        }
        if(!StringUtils.isEmpty(entity.getFileUrl())){
            List<FileVo> fileList = new ArrayList<>();
            fileList.addAll(getFiles(entity.getFileUrl(),"借调附件"));
            vo.setFiledoc(fileList);
        }
        vo.setBeginDate(DateUtils.format(entity.getOutTime()));
        vo.setEndDate(DateUtils.format(entity.getEndTime()));
        vo.setNdDate(DateUtils.format(entity.getOutTime()));
        vo.setReason(entity.getReason());
        sendMq(vo,EmployeeChangeConst.CHANGE_TYPE_TRANSFER);
        return R.ok();
    }

    @ApiOperation("离职异动更新接口")
    @Async("Neusoft")
    public R uploadDismissChange(DimissionInfoEntity entity){
        DismissVo vo = new DismissVo();
        EmployeeInfoEntity infoEntity = employeeInfoService.getByIdE(entity.getOid());
        DimissionSettlementEntity dimissionSettlementEntity = dimissionSettlementService.getByDimissionId(entity.getId());
        String name = infoEntity.getName();
        vo.setApplyDate(DateUtils.format(entity.getDimissionTime()));
        vo.setApplyId(entity.getId());
        vo.setCode(name+"的离职申请");
        vo.setDeptId(entity.getUnitId());
        vo.setEmpName(name);
        vo.setEmpCode(infoEntity.getCode());
        vo.setJobId(infoEntity.getJobId());
        if(infoEntity.getJobLevelType().equals(1)){
            vo.setZyzj(getCode(infoEntity.getJobLevelId()));
        }else{
            vo.setGlzj(getCode(infoEntity.getJobLevelId()));
        }
        vo.setLzDate(DateUtils.format(entity.getDimissionTime()));
        vo.setJoinDate(DateUtils.format(infoEntity.getHiredate()));
        vo.setLzWay(entity.getMode());
        vo.setLzType(entity.getDimissionType());
        //离职结算信息不为空的话用结算时的原因
        if(!ObjectUtils.isEmpty(dimissionSettlementEntity)){
            if(!StringUtils.isEmpty(dimissionSettlementEntity.getReason())){
                JSONObject object = JSON.parseObject(dimissionSettlementEntity.getReason());
                vo.setLzReason(object.getString("reasonText"));
            }
        }else{
            vo.setLzReason(entity.getReason());
        }
        vo.setOperator(entity.getApplyCode());
//        vo.setFiledoc(getFiles(entity.getBpmDetailUrl(),name+"的离职附件"));
        sendMq(vo,EmployeeChangeConst.CHANGE_TYPE_DIMISSION);
        return R.ok();
    }

    @ApiOperation("转正异动更新接口")
    @Async("Neusoft")
    public R uploadRegularChange(RegularBpmEntity entity,EmployeeBpmEntity bpmEntity,EmployeeInfoEntity infoEntity,BigDecimal baseSalary,BigDecimal moduleSalary){
        RegularVo vo = new RegularVo();
        //新员工转正
        if(ObjectUtils.isEmpty(entity)){
            String name = bpmEntity.getName();
            vo.setApplyId(bpmEntity.getOid());
            vo.setTitle(name+"的新员工转正申请");
            vo.setApplyDate(DateUtils.format(bpmEntity.getHiredate()));
            vo.setEmpName(name);
            vo.setEmpCode(bpmEntity.getCode());
            vo.setJoinDate(DateUtils.format(bpmEntity.getHiredate()));
            vo.setPosType("1");
            vo.setBeginDate(DateUtils.format(bpmEntity.getHiredate()));
            vo.setNconDate(DateUtils.format(DateUtils.addDateMonths(bpmEntity.getHiredate(),bpmEntity.getProbationday())));
            vo.setSyMonth(bpmEntity.getProbationday()+"");
            vo.setActualDate(DateUtils.format(bpmEntity.getRegularDay()));
            vo.setOldDeptId(ObjectUtils.isEmpty(bpmEntity.getOldDepartmentId())?bpmEntity.getUnitId():bpmEntity.getOldDepartmentId());
            vo.setNewDeptId(bpmEntity.getUnitId());
            vo.setOldJobId(ObjectUtils.isEmpty(bpmEntity.getOldJobId())?bpmEntity.getJobId():bpmEntity.getOldJobId());
            vo.setNewJobId(bpmEntity.getJobId());
            if(bpmEntity.getJobLevelType().equals(1)){
                vo.setOldZYZJ(getCode(bpmEntity.getJobLevelId()));
                vo.setNewZYZJ(getCode(bpmEntity.getJobLevelId()));
            }else{
                vo.setOldGLZJ(getCode(bpmEntity.getJobLevelId()));
                vo.setNewGLZJ(getCode(bpmEntity.getJobLevelId()));
            }
            vo.setKhsroc(bpmEntity.getScore());
            vo.setYsgd(baseSalary.toString());
            vo.setEmpMod(moduleSalary.toString());
            vo.setFiledoc(getFiles(bpmEntity.getRegularUrlIds(),name+"的转正申请"));
            if(ObjectUtils.isEmpty(infoEntity.getIsRegular())){
                vo.setSituation("1");
            } else if(infoEntity.getIsRegular().equals(1)){
                vo.setSituation("1");
            }else if(infoEntity.getIsRegular().equals(2)){
                vo.setSituation("2");
            }else if(infoEntity.getIsRegular().equals(4)){
                vo.setSituation("3");
            }
        }
        //管理转正
        else{
            String name = entity.getName();
            vo.setTitle(name+"的管理晋升转正申请");
            vo.setApplyId(entity.getId());
            vo.setApplyDate(DateUtils.format(entity.getApplyTime()));
            vo.setEmpName(name);
            vo.setEmpCode(entity.getCode());
            vo.setPosType("2");
            if(!entity.getRegularType().equals(2)){
                vo.setBeginDate(DateUtils.format(entity.getHiredate()));
                vo.setNconDate(DateUtils.format(DateUtils.addDateMonths(entity.getHiredate(),entity.getProbationday())));
                vo.setSyMonth(entity.getProbationday()+"");
            }else{
                vo.setBeginDate(DateUtils.format(DateUtils.addDateDays(entity.getHiredate(),-entity.getProbationday())));
                vo.setNconDate(DateUtils.format(entity.getHiredate()));
                vo.setSyMonth(entity.getProbationday()/30+"");
            }
            vo.setActualDate(DateUtils.format(entity.getRegularDay()));
            vo.setOldDeptId(entity.getBeforeUnitId());
            vo.setNewDeptId(entity.getUnitId());
            vo.setOldJobId(entity.getBeforeJobId());
            vo.setNewJobId(entity.getJobId());

            if("1".equals(entity.getBeforeLevelType())){
                vo.setOldZYZJ(getCode(entity.getBeforeJobLevelId()));
            }else{
                vo.setOldGLZJ(getCode(entity.getBeforeJobLevelId()));
            }

            if(entity.getJobLevelType().equals(1)){
                vo.setNewZYZJ(getCode(entity.getJobLevelId()));
            }else{
                vo.setNewGLZJ(getCode(entity.getJobLevelId()));
            }
            vo.setKhsroc(entity.getScore());
            vo.setYsgd(baseSalary.toString());
            vo.setEmpMod(moduleSalary.toString());
            vo.setFiledoc(getFiles(entity.getUrlIds(),name+"的转正申请"));
            if(ObjectUtils.isEmpty(entity.getIsRegular())){
                vo.setSituation("1");
            } else if(entity.getIsRegular().equals(1)){
                vo.setSituation("1");
            }else if(entity.getIsRegular().equals(2)){
                vo.setSituation("2");
            }else if(entity.getIsRegular().equals(4)){
                vo.setSituation("3");
            }

        }



        sendMq(vo,EmployeeChangeConst.CHANGE_TYPE_REGULAR);
        return R.ok();
    }

    /**
     * 获取附件
     * @param url
     * @param name
     * @return
     */
    public List<FileVo> getFiles(String url,String name){
        List<FileVo> list  = new ArrayList<>();
        if(!StringUtils.isEmpty(url)){
            String[] urls = url.split(",");
            for(String u:urls){
                FileVo file = new FileVo();
                file.setFileUrl(u);
                file.setFileName(name);
                list.add(file);
            }
        }
        return list;
    }

    public void sendMq(Object object,String type){
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSON(object).toString());
        jsonObject.put("type",type);
        messageSender.send(employeeChangeMqConfig.SMS_EXCHANGE,employeeChangeMqConfig.SMS_ROUTING_KEY,jsonObject.toJSONString());
    }

    public String getCode(Long id){
        return jobController.jobLevelCodeMap.get(id);
    }

    @GetMapping("/test20")
    public void test(){
       TransferInfoEntity entity =  transferInfoService.getByIdE(59l);
        uploadTransferChange(entity,new BigDecimal(190000),new BigDecimal(100000));
    }

}
